package com.ogilvy.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ogilvy.cms.bean.CmsUser;
import com.ogilvy.cms.dao.CmsUserDao;
import com.ogilvy.cms.service.CmsUserService;
import com.ogilvy.frame.service.BaseServiceImpl;

@Service
public class CmsUserServiceImpl extends BaseServiceImpl implements CmsUserService{
	
	@Autowired
	protected CmsUserDao cmsUserDao;
	
	public CmsUser add(CmsUser cmsUser) {
		CmsUser cmsuser = cmsUserDao.save(cmsUser);
		return cmsuser;
	}

	public boolean del(Integer cmuId) {
		cmsUserDao.deleteById(cmuId);
		return true;
	}

	public boolean modify(CmsUser cmsUser) {
		cmsUserDao.update(cmsUser);
		return true;		
	}

	public List<CmsUser> query(CmsUser cmsuser) {
		if(isEmpty(cmsuser.getCmuName())){
			return cmsUserDao.findAll();
		}
		return cmsUserDao.findByProperty("cmuName", cmsuser.getCmuName());
	}
	
	/** 登录判断 */
	public CmsUser login(String cmuName, String cmuPassword){
		if(!(isEmpty(cmuName) || isEmpty(cmuPassword))){ 
			List<CmsUser> list = cmsUserDao.findByProperty("cmuName", cmuName);
			if(!list.isEmpty()){
				CmsUser cu = list.get(0);
				if(cu.getCmuPassword().equals(cmuPassword)){
					return cu;
				}
			}
		}
		return null;
	}
	 /**根据筛选条件查询相关信息*/
	public List<CmsUser> queryByScreen(Map<String, String> screenMap) {
		return cmsUserDao.getListByScreen(screenMap);
	}
	
	/**查询是否已经存在数据*/
    public Boolean isExistsObj(String cmuName){
    	 List list=cmsUserDao.findByProperty("cmuName",cmuName);
    	 if (list == null || list.size()==0) {
 			return false;
 		}else
 		{
 			return true;
 		}
    }
}
